package Operaciones;

import java.io.*;
import java.util.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import BasedeDatos.*;

public class EscribirFichero {
		Connection con;
	
		public void generarsolucionSQL(String direccion) throws IOException, SQLException{
			ArrayList l = new ArrayList();
			con = Conexion.conexion();
			Statement stmt = con.createStatement();
			String q = "SELECT reparacion FROM npcasignado WHERE reparada = 1;";
			try{
				ResultSet rs = stmt.executeQuery(q);
				while(rs.next()){
					l.add(rs.getString("reparacion"));
					
				}
			}catch(SQLException e){}
			
			Statement stmt2 = con.createStatement();
			String q2 = "SELECT reparacion FROM misionasignado WHERE reparada = 1;";
			try{
				ResultSet rs2 = stmt2.executeQuery(q2);
				while(rs2.next()){
					l.add(rs2.getString("reparacion"));
					
				}
			}catch(SQLException e){}
			
			
			Statement stmt3 = con.createStatement();
			String q3 = "SELECT reparacion FROM itemasignado WHERE reparada = 1;";
			try{
				ResultSet rs3 = stmt3.executeQuery(q3);
				while(rs3.next()){
					l.add(rs3.getString("reparacion"));
					
				}
			}catch(SQLException e){}
			
			FileWriter fichero = new FileWriter(direccion);
			try {
			PrintWriter pw = pw = new PrintWriter(fichero);
			System.out.println(direccion);
			Iterator it = l.iterator();
			while(it.hasNext()){
				String res = (String) it.next();
                pw.println(res);
                pw.println("");
			}
			 fichero.close();
			}
			catch (IOException ioe) {
			ioe.printStackTrace();
		}
			
		}
		
		public void generarsolucionC(String direccion) throws IOException, SQLException{
			ArrayList l = new ArrayList();
			con = Conexion.conexion();
			Statement stmt = con.createStatement();
			String q = "SELECT reparacion FROM spellasignado WHERE reparada = 1;";
			try{
				ResultSet rs = stmt.executeQuery(q);
				while(rs.next()){
					l.add(rs.getString("reparacion"));
					
				}
			}catch(SQLException e){}
			FileWriter fichero = new FileWriter(direccion);
			try {
			PrintWriter pw = pw = new PrintWriter(fichero);
			System.out.println(direccion);
			Iterator it = l.iterator();
			while(it.hasNext()){
				String res = (String) it.next();
                pw.println(res);
                pw.println("");
			}
			 fichero.close();
			}
			catch (IOException ioe) {
			ioe.printStackTrace();
		}
		}
	}


